from __future__ import division, print_function
import time

from direct.directbase import DirectStart
from pvis import *

# This runs at approximately 26.5 fps with L=N=4


boxes = []

#L = 6
#N = 20
L = 6
N = 10
#scene.range.x = 2*L

for x in range(N):
    for y in range(N):
        for z in range(N):
            b = box(color=(x/N,y/N,z/N), 
                    pos=(L*(x/(N-1)-.5),L*(y/(N-1)-.5),L*(z/(N-1)-.5)), 
                    size=(.6*L/N,.4*L/N,.6*L/N))
            boxes.append(b)


print('Num Boxes = %d' % len(boxes))
rate(10000)
counter = 0
ts = time.time()
t = 0
dt = 0.01
qr = Quat()
qr.setFromAxisAngleRad(dt, (0,1,0))

def loop(task):
    for box in boxes:
        box.q = qr * box.q
        #box.rotate(angle=dt, q=vis3d.yAxis)
        #box.axis = ( sin(t), 0, cos(t) )
    
    return task.cont

base.disableMouse()
base.camera.setPos(3*L, 0, 0)
base.camera.lookAt(0, 0, 0)
base.camera.setR(90)
#base.oobe() # Allow the mouse to work also

Run(loop)

